﻿/***************************************************************************
 *		ElGee Google Chart API Helper
 *		Copyright(C) 2011 by Laurent Geffroy lgeffroy@gmail.com
 * 
 *		This program is free software; you can redistribute it and/or 
 *		modify it under the terms of the GNU General Public License as
 *		published by the Free Software Foundation; either version 2 of 
 *		the License, or (at your option) any later version.
 *		
 *		This program is distributed WITHOUT ANY WARRANTY; without even the
 *		implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 *		See the GNU General Public License for more details.
 *	
 *      For particular licensing, please contact me at lgeffroy@gmail.com
 *****************************************************************************/


using System;
using System.Text;

namespace ElGee.Google.Charts
{
    /// <summary>
    /// Horizontal Axis Class
    /// </summary>
    public class HAxis : Axis
    {
        /// <summary>
        /// Gets or sets a value indicating whether [slanted text].
        /// If true, draw the horizontal axis text at an angle, to help fit more text along the axis; if false, draw horizontal axis text upright. Default behavior is to slant text if it cannot all fit when drawn upright.
        /// </summary>
        /// <value>slantedText</value>
        public TypeOfSlantedText SlantedText { get; set; }

        /// <summary>
        /// Gets or sets the slanted text angle (1-90)
        /// The angle of the horizontal axis text, if it's drawn slanted. Ignored if hAxis.slantedText is false, or is in auto mode, and the chart decided to draw the text horizontally.
        /// </summary>
        /// <value>slantedTextAngle.</value>
        public UInt32 SlantedTextAngle { get; set; }

        /// <summary>
        /// Gets or sets the max alternation.
        /// Maximum number of levels of horizontal axis text. If axis text labels become too crowded, the server might shift neighboring labels up or down in order to fit labels closer together. This value specifies the most number of levels to use; the server can use fewer levels, if labels can fit without overlapping.
        /// </summary>
        /// <value>The max alternation.</value>
        public UInt32 MaxAlternation { get; set; }


        /// <summary>
        /// Gets or sets the show text every.
        /// How many horizontal axis labels to show, where 1 means show every label, 2 means show every other label, and so on. Default is to try to show as many labels as possible without overlapping.
        /// </summary>
        /// <value>The show text every.</value>
        public UInt32 ShowTextEvery { get; set; }

        /// Gets a value indicating whether this instance is empty.
        /// </summary>
        /// <value><c>true</c> if this instance is empty; otherwise, <c>false</c>.</value>
        public override bool IsEmpty
        {
            get
            {
                if (!base.IsEmpty)
                    return false;

                if (((SlantedText == TypeOfSlantedText.Angled) || (SlantedText == TypeOfSlantedText.Upright))
                    && (SlantedTextAngle != 30) && (MaxAlternation != 2) && (ShowTextEvery != 0))
                    return false;
                return true;
            }
        }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            if (IsEmpty)
                return String.Empty;

            StringBuilder sb = new StringBuilder();
            if (!base.IsEmpty)
                sb.Append(base.ToString());

            switch (SlantedText)
            {
                case TypeOfSlantedText.Angled:
                    sb.Append("slantedText: true,");
                    break;
                case TypeOfSlantedText.Upright:
                    sb.Append("slantedText: false,");
                    break;
            }

            if (SlantedTextAngle > 90)
                SlantedTextAngle = 30;

            if (SlantedTextAngle != 30)
                sb.Append("slantedTextAngle: ").Append(SlantedTextAngle).Append(",");

            if (MaxAlternation != 2)
                sb.Append("maxAlternation: ").Append(MaxAlternation).Append(",");

            if (ShowTextEvery != 0)
                sb.Append("showTextEvery: ").Append(ShowTextEvery).Append(",");

            // Removing the last comma
            sb.Remove(sb.Length - 1, 1);

            return sb.ToString();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="HAxis"/> class.
        /// </summary>
        public HAxis() : base()
        {
            SlantedText = TypeOfSlantedText.Automatic;
            SlantedTextAngle = 30;
            MaxAlternation = 2;
            ShowTextEvery = 0;
        }
    }
}
